﻿using System;
using System.Globalization;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;

namespace be.metanous.mvvm.converters
{
    public class DataTemplateSelectorConverter : IMultiValueConverter 
    {
        public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
        {
            if (parameter is DataTemplateSelector && values != null && values.Length > 1 && values[1] is DependencyObject)
            {
                return (parameter as DataTemplateSelector).SelectTemplate(values[0], (DependencyObject) values[1]);
            }
            return null;
        }

        public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
        {
            return null;
        }
    }
}
